package com.bytedance.scenedemo.navigation.popinterupt;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scene.navigation.OnBackPressedListener;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.navigation.singletask.SingleTaskDemoScene1;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

/**
 * Created by JiangQi on 8/3/18.
 */
public class PopInterruptScene extends Scene {
    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_single_task_demo_scene,container,false);
        ScrollView svMain= (ScrollView) layout.findComponentById(ResourceTable.Id_sv_single_task_demo_scene_main);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_hint);
        Text textPath= (Text) layout.findComponentById(ResourceTable.Id_text_single_task_demo_scene_path);
        Button btnGoTo= (Button) layout.findComponentById(ResourceTable.Id_btn_single_task_demo_scene_goto);

        svMain.setBackground(ColorUtil.getMaterialColor(0));
        textHint.setText(getClassName());
        textPath.setText(SceneExtensions.getNavigationScene(this).getStackHistory());

        btnGoTo.setVisibility(Component.HIDE);

        SceneExtensions.getNavigationScene(this).addOnBackPressedListener(this, new OnBackPressedListener() {
            private long time=0;
            @Override
            public boolean onBackPressed() {
                if(System.currentTimeMillis()-time>2*1000){
                    showToast("再按一次返回");
                    time=System.currentTimeMillis();
                    return true;
                }
                return false;
            }
        });

        return layout;
    }

}
